package com.gitee.huxing.course.controller;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.gitee.huxing.course.service.PlatFormOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.controller
 * @ClassName: TestController
 * @Author: huxing
 * @DateTime: 2021-09-17 下午4:32
 */
@RestController
public class TestController {

    @Autowired
    PlatFormOrderService service;

    @RequestMapping("/api/v1/apply")
    public String generalOrder() throws RuntimeException{
        return "下单成功, 您的购买订单号为: " +  this.service.purchase();
    }

    @RequestMapping("/api/v1/testBatch")
    public String testBatch() throws RuntimeException{
        long startTime = System.currentTimeMillis();
        this.service.batchPurchase();
        long endTime = System.currentTimeMillis();
        return "批量下单成功, 总计耗时: " + (endTime-startTime) + "ms";
    }

    @RequestMapping("/api/v1/getOrder/{orderId}")
    public String queryOrder(@PathVariable("orderId") String orderId) throws RuntimeException{
        return "您好，您的订单记录为: " + JSONObject.toJSONString(this.service.queryOrder(orderId));
    }
}
